<template>
  <div class="app-container">
     <eHeader :query="query" :dict="dict" :sup_this="sup_this"/>
    <!--表格渲染-->
    <el-table v-loading="loading" :data="data" size="small" style="width: 100%;">
      <el-table-column prop="worker_name" label="员工姓名"/>
      <el-table-column prop="cart_num" label="卡号"/>
      <el-table-column label="部门">
        <template slot-scope="scope">
          <div v-for="item in dict.dept" :key="item.id">
            <span v-if="scope.row.dept_id==item.id">{{ item.name }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="job_name" label="职位">
        <template slot-scope="scope">
          <div v-for="item in dict.job" :key="item.id">
            <span v-if="scope.row.job_id==item.id">{{ item.name }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="device_name" label="设备"/>
      <el-table-column prop="label" label="进出标识"/>
      <el-table-column prop="pass_time" label="考勤时间">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.pass_time) }}</span>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <el-pagination
      :total="total"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"/>
  </div>
</template>

<script>
import initData from '@/mixins/initData'
import { del,getDict } from '@/api/workerAttendance'
import { parseTime } from '@/utils/index'
import eHeader from './module/header'
import edit from './module/edit'
export default {
  components: { eHeader, edit },
  mixins: [initData],
  data() {
    return {
      delLoading: false, sup_this: this,dict: {}
    }
  },
  created() {
    this.$nextTick(() => {
      this.init()
      this.getDict()
    })
  },
  methods: {
    parseTime,
    getDict(){
      getDict().then(res => {
        this.dict = res
      }).catch(err => {
        console.log(err.response.data.message)
      })
    },
    beforeInit() {
      this.url = 'api/workerAttendance'
//      const sort = 'id,desc'
      this.params = { page: this.page, size: this.size}
      const query = this.query
      const startTime = query.startTime
      const endTime = query.endTime
      const cartNum = query.cartNum
      const workerName = query.workerName
      const deptId = query.deptId
      const jobId = query.jobId
      if (startTime) {
        this.params['startTime'] = startTime
      }
      if (endTime) {
        this.params['endTime'] = endTime
      }
      if (workerName) {
        this.params['workerName'] = workerName
      }
      if (cartNum) {
        this.params['cartNum'] = cartNum
      }
      if (deptId) {
        this.params['deptId'] = deptId
      }
      if (jobId) {
        this.params['jobId'] = jobId
      }
      return true
    },
    subDelete(id) {
      this.delLoading = true
      del(id).then(res => {
        this.delLoading = false
        this.$refs[id].doClose()
        this.init()
        this.$notify({
          title: '删除成功',
          type: 'success',
          duration: 2500
        })
      }).catch(err => {
        this.delLoading = false
        this.$refs[id].doClose()
        console.log(err.response.data.message)
      })
    }
  }
}
</script>

<style scoped>

</style>
